package com.yanqu.road.dao.impl.activity.eggs;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.eggs.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;

public class EggsActivityConfigDaoImpl extends TempDao {

    public Map<Integer, EggsSceneConfig> getEggsSceneConfigMap(int activityId) {
        String get1Sql = "select * from t_s_activity_guangfu_scene where activityId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, EggsSceneConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get1Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EggsSceneConfig data = new EggsSceneConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setEventId(rs.getInt("eventId"));
                data.setType(rs.getInt("type"));
                data.setDesc(rs.getString("desc"));
                data.setWeight(rs.getInt("weight"));
                data.setConsume(rs.getString("consume"));
                data.setReward(rs.getString("reward"));
                data.setExtendParam(rs.getString("extendParam"));
                dataMap.put(data.getEventId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, EggsClassRoomConfig> getEggsClassRoomConfigMap(int activityId) {
        String get1Sql = "select * from t_s_activity_guangfu_classroom where activityId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, EggsClassRoomConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get1Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EggsClassRoomConfig data = new EggsClassRoomConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setTitle(rs.getString("title"));
                data.setContent(rs.getString("content"));
                data.setPreface(rs.getString("preface"));
                data.setKeyExp(rs.getString("keyExp"));
                data.setWordAnalysis(rs.getString("wordAnalysis"));
                data.setTest(rs.getString("test"));
                data.setRewards(rs.getString("rewards"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, EggsTestConfig> getEggsTestConfigMap(int activityId) {
        String get1Sql = "select * from t_s_activity_guangfu_test where activityId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, EggsTestConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get1Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EggsTestConfig data = new EggsTestConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setDesc(rs.getString("desc"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, EggsSongConfig> getEggsSongConfigMap(int activityId) {
        String get1Sql = "select * from t_s_activity_guangfu_song where activityId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, EggsSongConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get1Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EggsSongConfig data = new EggsSongConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setIcon(rs.getInt("icon"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setRewards(rs.getString("rewards"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }

    public Map<Integer, EggsStoryConfig> getEggsStoryConfigMap(int activityId) {
        String get1Sql = "select * from t_s_activity_guangfu_story where activityId=?";
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, EggsStoryConfig> dataMap = new HashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get1Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                EggsStoryConfig data = new EggsStoryConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setIcon(rs.getInt("icon"));
                data.setTab(rs.getString("tab"));
                data.setDesc(rs.getString("desc"));
                data.setContent(rs.getString("content"));
                data.setRewards(rs.getString("rewards"));
                dataMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
